package practice;

/**
 * @Description: https://leetcode.cn/problems/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof/
 * @Author Ammar
 * @Create 2023/7/20 20:37
 */
public class _剑指offer_62_圆圈中最后剩下的数字 {
    public int lastRemaining(int n, int m) {
        return f(n, m);
    }

    private int f (int n, int m) {
        if (n == 1) return 0;
        int res = (f(n - 1, m) + m) % n;
        return res;
    }

    public int lastRemaining1(int n, int m) {
        int res = 0;
        for (int i = 2; i <= n; i++) {
            res = (res + m) % i;
        }
        return res;
    }

    public static void main(String[] args) {
        System.out.println(new _剑指offer_62_圆圈中最后剩下的数字().lastRemaining(11, 3));
    }
}
